﻿using DFGK.IService;
using DFGK.Service;
using DFGK_WMS.Common;
using DFGK_WMS.Model.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualBasic;
using System.Collections.Generic;
using System.Net.Mime;
using System.Security.Claims;

namespace DFGK_WMS.WebAPI.Controllers.PC.装备维修管理
{
    /// <summary>
    /// 网络地址统计
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "PC")]
    public class NetworkAddressController : BaseController
    {
        private readonly INetworkAddressService networkAddressService;
        /// <summary>
        /// 网络地址统计
        /// </summary>
        /// <param name="environment"></param>
        /// <param name="networkAddressService"></param>
        public NetworkAddressController(IWebHostEnvironment environment, INetworkAddressService networkAddressService) : base(environment)
        {
            this.networkAddressService = networkAddressService;
        }
        /// <summary>
        /// 网络地址统计
        /// </summary>
        /// <param name="netAddress">网站地址</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAllNetworkAddress(string? netAddress, int pageIndex = 1, int pageSize = 5)
        {
            if (pageIndex <= 0 || pageSize <= 0)
            {
                BaseResult.Result("400", "分页条件有误！");
            }
            var list = networkAddressService.GetNetworkAddress(netAddress, pageIndex, pageSize, out var totalCount);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", totalCount));
            }
            return Ok(BaseResult.Result(null, "查询失败！", "500", 0));
        }

        /// <summary>
        /// 网络地址导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult NetworkAddressDown()
        {
            var list = networkAddressService.GetNetMsgDown();
            if (list != null)
                return NetworkAddressDown(list);
            else
                return Ok();
        }
    }
}
